﻿package view.selectView.control
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.geom.*;
    import morn.core.components.*;

    public class SelectViewBufferItem extends Container
    {
        private var buffer:Object;
        private var _disposed:Boolean;
        private var _icon:Image;
        private var _showTips:Boolean;
        private var _timerId:int;

        public function SelectViewBufferItem(param1:Object)
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            this.buffer = param1;
            _loc_2 = ConfigDictionary.data.buffer;
            _loc_3 = _loc_2[param1.id];
            param1.data = _loc_3;
            this._icon = new Image("assets/images/icon/buffer/" + _loc_3.icon + ".jpg");
            this._icon.width = 24;
            this._icon.height = 24;
            addChild(this._icon);
            addEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            if (param1.dispelTime >= 0)
            {
                this._timerId = SecondTimerUtil.instance.addSecondTask(this.timerHandler);
            }
            return;
        }// end function

        private function timerHandler() : void
        {
            if (this.buffer.dispelTime > 0)
            {
                var _loc_1:* = this.buffer;
                var _loc_2:* = this.buffer.dispelTime - 1;
                _loc_1.dispelTime = _loc_2;
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            if (this.buffer && this.buffer.data)
            {
                _loc_3 = "永久";
                if (this.buffer.dispelTime >= 0)
                {
                    _loc_3 = TimeDataFormatUtil.getLeftTimeStr(this.buffer.dispelTime);
                }
                if (this.buffer.type == 0)
                {
                    _loc_2 = "{FFFF01#12#" + this.buffer.data.name + "}\n{FF6600#12#" + _loc_3 + "}\n{FFffff#12#" + this.buffer.data.tips + "}";
                }
                else
                {
                    _loc_2 = "{FFFF01#12#" + this.buffer.data.name + "}\n{FF6600#12#" + _loc_3 + "}\n{FFffff#12#" + this.buffer.data.tips1 + "}";
                }
                ModelProxy.change("tips", "normal", {data:Html.covert(_loc_2), p:new Point(2, 2)});
            }
            addEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            removeEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            return;
        }// end function

        public function clearTimer() : void
        {
            if (this._timerId > 0)
            {
                SecondTimerUtil.instance.removeTask(this._timerId);
                this._timerId = 0;
            }
            return;
        }// end function

        public function dispose() : void
        {
            this.clearTimer();
            this.buffer = null;
            if (this._showTips)
            {
                ModelProxy.change("tips", "state", "close");
            }
            this._showTips = false;
            this._disposed = true;
            if (this._icon)
            {
                removeChild(this._icon);
                this._icon = null;
            }
            return;
        }// end function

    }
}
